package edu.mtu.citizenscience.cs.sdk.uploader.model;

import java.util.Date;
/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * A entry in the apps database on a table row
 */
public class Entry<E> {
	// name of the entry same as the column it is stored in
	protected String name;
	// the type of the entry
	protected EntryType type;
	// the value stored in the entry
	protected E value;
	
	/**
	 * Create the entry
	 * 
	 * @param   void
	 * @return	void
	 */
	public Entry() {  }
	
	/**
	 * Create the entry
	 * 
	 * @param   name - String - the entry name
	 * @param	value - E - the entry value
	 * @return	void
	 */
	public Entry(String name, EntryType type, E value)
	{
		this.name = name;
		this.type = type;
		this.value = value;
	}
	
	/**
	 * Get the entry name
	 * 
	 * @param   void
	 * @return	String - the entry name
	 */
	public String getName()
	{
		return this.name;
	}

	/**
	 * Set the entry name
	 * 
	 * @param   name - String - the entry name
	 * @return	void
	 */
	public void setName(String name)
	{
		this.name = name;
	}
	
	/**
	 * Get the entry type
	 * 
	 * @param   void
	 * @return	EntryType - the entry type
	 */
	public EntryType getType()
	{
		return this.type;
	}
	
	/**
	 * Set the entry type
	 * 
	 * @param   type - EntryType - the entry type
	 * @return	void
	 */
	public void setType(EntryType type)
	{
		this.type = type;
	}
	
	/**
	 * Get the entry value
	 * 
	 * @param   void
	 * @return	E - the entry value
	 */
	public String getValue()
	{
		// check if the value type is date
		if (this.getType() == EntryType.TYPE_DATE)
		{
			// convert the date value to a long
			return Long.toString(((Date) this.value).getTime());
		}

		// convert the value to a string
		return this.value.toString();
	}
	
	/**
	 * Set the entry value
	 * 
	 * @param   value - E - the entry value
	 * @return	void
	 */
	public void setValue(E value)
	{
		this.value = value;
	}
	
}
